﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QXBook.Service;
using System.Web;
using QXBook.Utils;
using QXBook.Model;
using System.Configuration;
using System.Web.SessionState;

namespace QXBook.Handlers.AjaxHandlers
{
    public class AddShoppingCart : AjaxHandler, IRequiresSessionState
    {
        public override string GetBusinessData(HttpContext context)
        {
            int productID = CommonUtils.ToInt(context.Request["id"]);

            ProductInfo product = ServiceFactory.CreateInstance<ProductService>().GetModel(productID);

            object username = SessionState.Get(ConfigurationManager.AppSettings["UserSessionName"]);

            UsersInfo user = null;
            if (username != null)
            {
                user = ServiceFactory.CreateInstance<UsersService>().GetUsersInfo(username.ToString());
            }
            int nTotal = ServiceFactory.CreateInstance<ShoppingCartService>().InsertToCart(user, product);

            return nTotal.ToString();
        }
    }
}
